// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "AudioMixerBlueprintLibrary.h"
#include "GameSettingValueDiscreteDynamic.h"

#include "LyraSettingValueDiscreteDynamic_AudioOutputDevice.generated.h"

class UObject;
struct FFrame;

enum class EAudioDeviceChangedRole : uint8;

/**
 * 音频输出设备离散动态值设置类，继承自UGameSettingValueDiscreteDynamic
 */
UCLASS()
class ULyraSettingValueDiscreteDynamic_AudioOutputDevice : public UGameSettingValueDiscreteDynamic
{
	GENERATED_BODY()
	
public:

	virtual ~ULyraSettingValueDiscreteDynamic_AudioOutputDevice() = default;

	/** UGameSettingValueDiscrete */
	/**
	 * 根据索引设置离散选项
	 */
	virtual void SetDiscreteOptionByIndex(int32 Index) override;

protected:

	/**
	 * 初始化时调用
	 */
	virtual void OnInitialized() override;

public:

	UFUNCTION()
	/**
	 * 音频输出设备获取完成时调用
	 */
	void OnAudioOutputDevicesObtained(const TArray<FAudioOutputDeviceInfo>& AvailableDevices);

	UFUNCTION()
	/**
	 * 设备交换完成时调用
	 */
	void OnCompletedDeviceSwap(const FSwapAudioOutputResult& SwapResult);

	UFUNCTION()
	/**
	 * 设备添加或移除时调用
	 */
	void DeviceAddedOrRemoved(FString DeviceId);

	UFUNCTION()
	/**
	 * 默认设备更改时调用
	 */
	void DefaultDeviceChanged(EAudioDeviceChangedRole InRole, FString DeviceId);

protected:

	TArray<FAudioOutputDeviceInfo> OutputDevices; // 输出设备数组
	FString CurrentDeviceId; // 当前设备ID
	FString SystemDefaultDeviceId; // 系统默认设备ID
	int32 LastKnownGoodIndex = 0; // 最后已知良好索引
	bool bRequestDefault = false; // 是否请求默认

	FOnAudioOutputDevicesObtained DevicesObtainedCallback; // 设备获取完成回调
	FOnCompletedDeviceSwap DevicesSwappedCallback; // 设备交换完成回调
};